package com.personal.controller;

import com.personal.pojo.LoginInfo;
import com.personal.pojo.Result;
import com.personal.pojo.User;
import com.personal.server.UserServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private UserServer userServer;

    @RequestMapping("/login")
    public Result login(@RequestBody User user){
        log.info("{}登录", user.getName());
        LoginInfo loginInfo = userServer.login(user);
        if(loginInfo != null){
            return Result.success(loginInfo);
        }
        return Result.error("用户名或密码错误");
    }

}
